#region Namespace Inclusions
using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Threading;

using SCI_actuator.Properties;
#endregion
namespace SCI_actuator
{
    public partial class sci_settings : Form
    {
        menu_control menu;
        private xmlrw scixml;

        public sci_settings(menu_control mc)
        {
            InitializeComponent();
            menu = mc;
            scixml = new xmlrw();
            Initial();
        }
        private void Initial()
        {
            cmbBaudRate.Text = scixml.Read_Baudrate();
            cmbDataBits.Text = scixml.Read_Databits();
            cmbDataMode.Text = scixml.Read_Datamode();
            cmbParity.Text = scixml.Read_Parity();
            cmbStopBits.Text = scixml.Read_Stopbits();

            cmbPortName.Items.Clear();
            foreach (string s in SerialPort.GetPortNames())
                cmbPortName.Items.Add(s);
            if (cmbPortName.Items.Contains(scixml.Read_Portname())) cmbPortName.Text = scixml.Read_Portname();
            else if (cmbPortName.Items.Count > 0) cmbPortName.SelectedIndex = 0;
        }
        private void true_Btn_Click(object sender, EventArgs e)
        {
            scixml.Write_Baudrate(cmbBaudRate.Text);
            scixml.Write_Databits(cmbDataBits.Text);
            scixml.Write_Datamode(cmbDataMode.Text);
            scixml.Write_Parity(cmbParity.Text);
            scixml.Write_Portname(cmbPortName.Text);
            scixml.Write_Stopbits(cmbStopBits.Text);

            menu.BandRate = cmbBaudRate.Text;
            menu.DataBits = cmbDataBits.Text;
            menu.DataMode = cmbDataMode.Text;
            menu.Parity = cmbParity.Text;
            menu.PortName = cmbPortName.Text;
            menu.StopBit = cmbStopBits.Text;
            menu.save_sci_setting = true;
            this.Hide();
            this.Dispose();
        }
    }
}